const Service = require('egg').Service

class UserInfoService extends Service {
	async update(id, body) {
		try {
			await this.ctx.model.UserInfo.update(
				{ ...body },
				{
					where: { userId: id },
				}
			)
			return 'success'
		} catch (e) {
			console.log(e)
			return '不存在该数据'
		}
	}
	async show(id) {
		const body = await this.ctx.model.UserInfo.findOne({
			include: [
				{
					model: this.ctx.model.Province,
					attributes: ['name','provinceCode'],
				},
				{
					model: this.ctx.model.City,
					attributes: ['name','cityCode'],
				},
				{
					model: this.ctx.model.Area,
					attributes: ['name','areaCode'],
				},
			],
			where: { userId: id },
		})
		if (body == null) {
			return {
				status: '不存在该数据',
			}
		} else {
			return {
				body,
				status: 'success',
			}
		}
	}
}

module.exports = UserInfoService
